﻿using System;
using SharpArch.Testing.NUnit;
using NUnit.Framework;
using SharpArch.Data.NHibernate;
using gnodotnet.Data.NHibernateMaps;
using SharpArch.Core.PersistenceSupport;
using gnodotnet.Core.MailingList;
using SharpArch.Testing.NHibernate;
using SharpArch.Web.NHibernate;
using gnodotnet.Data;
using gnodotnet.Core;
using SharpArch.Testing.NUnit.NHibernate;

namespace Tests.gnodotnet.Data.CreateUpdate {
    [TestFixture]
    [Category("DatabaseTests")]
    public class SavingReceipt : RepositoryTestsBase {
        protected override void LoadTestData() {
            
        }
        //[SetUp]
        //public virtual void SetUp() {
        //    NHibernateSession.SessionFactory = null;
        //    NHibernateSession.Storage = null;

        //    string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies();
        //    NHibernateSession.Init(new SimpleSessionStorage(factoryKey), mappingAssemblies,
        //        new AutoPersistenceModelGenerator().Generate(),
        //        "../../../../app/gnodotnet.Web/NHibernate.config");

        //    _session = NHibernateSession.CurrentFor(factoryKey);
        //    _repository= new Repository<Recipient>();
        //}
        //[TearDown]
        //public virtual void TearDown() {
        //    if (NHibernateSession.Storages[factoryKey].Session != null) {
        //        NHibernateSession.Storages[factoryKey].Session.Dispose();
        //    }

        //    NHibernateSession.SessionFactory = null;
        //    NHibernateSession.Storage = null;
        //}

        private NHibernate.ISession _session;
        string factoryKey = "nhibernate.current_session";
        [Test]
        [Transaction]
        public void CanCreate() {
            _repository.SaveOrUpdate(new Recipient() { Name = "Test", Email = "test@test.com" });
        }
        [Test]
        public void FindOne_WithNoResults_ReturnsNull() {
            _repository.FindOne(new EntitySpec() { { MembersOf<Recipient>.GetName(x=>x.Name), "thisdoesnotexist" } }).ShouldBeNull();
        }
        private IRepository<Recipient> _repository= new Repository<Recipient>();
    }
}
